#include<iostream>
#include"Thread.hpp"
#include"ThreadPool.hpp"
#include"log.hpp"
#include"LockGuard.hpp"
#include<memory>  // ? 智能指针
#include"Task.hpp"

int main()
{
    //使用智能指针进行托管，防止内存泄漏
    std::unique_ptr<ThreadPool<Task>> tp(new ThreadPool<Task>());

    tp->Start();

    while(true)
    {
        int data1=rand()%10+1; //[1,10]
        
        //data1和data2因为执行太快，产生的值可能一样
        usleep(rand()%123);

        int data2=rand()%10+1; //[1,10]
        usleep(rand()%123);
        char oper = opers[rand()%opers.size()];

        Task t(data1,data2,oper);

        tp->Push(t);

        string task_string = t.PrintTask();
        cout<<"productor task: "<<task_string<<endl;
        sleep(1);
        //sleep(1);
    }
    
    tp->Wait();
}